#ifndef __BSP_USART_H
#define __BSP_USART_H

#include "stm32f10x.h"
#include <stdio.h>
#include "debug/bsp_gpio_debug.h"
#include "rd03/bsp_gpio_rd03.h"

#pragma diag_suppress 870

#define DATA_SIZE 2048
typedef struct
{
    uint32_t flag;
    uint32_t len;
    uint8_t data[DATA_SIZE];
}USART_DataTypeDef;


extern USART_DataTypeDef debug_receive_data;
extern USART_DataTypeDef rd03_receive_data;

#if (DEBUG_USART_NUM == 1)

    #define DEBUG_USARTX   			        USART1
    #define DEBUG_USARTX_CLK_PORT 	        RCC_APB2Periph_USART1				
    #define DEBUG_APBXCLKCMD   			    RCC_APB2PeriphClockCmd	
    #define DEBUG_BAUDRATE   			    115200
            
    #define DEBUG_IRQ                       USART1_IRQn
    #define DEBUG_IRQHANDLER                USART1_IRQHandler
    
#elif (DEBUG_USART_NUM == 2)

    #define DEBUG_USARTX   			        USART2
    #define DEBUG_USARTX_CLK_PORT 	        RCC_APB1Periph_USART2				
    #define DEBUG_APBXCLKCMD   			    RCC_APB1PeriphClockCmd	
    #define DEBUG_BAUDRATE   			    115200
            
    #define DEBUG_IRQ                       USART2_IRQn
    #define DEBUG_IRQHANDLER                USART2_IRQHandler
    
#elif (DEBUG_USART_NUM == 3)

    #define DEBUG_USARTX   			        USART3
    #define DEBUG_USARTX_CLK_PORT 	        RCC_APB1Periph_USART3				
    #define DEBUG_APBXCLKCMD   			    RCC_APB1PeriphClockCmd	
    #define DEBUG_BAUDRATE   			    115200		
            
    #define DEBUG_IRQ                       USART3_IRQn
    #define DEBUG_IRQHANDLER                USART3_IRQHandler
    
#endif

#if (RD03_USART_NUM == 1)

    #define RD03_USARTX   			        USART1
    #define RD03_USARTX_CLK_PORT 	        RCC_APB2Periph_USART1				
    #define RD03_APBXCLKCMD   			    RCC_APB2PeriphClockCmd	
    #define RD03_BAUDRATE   			    115200
            
    #define RD03_IRQ                       USART1_IRQn
    #define RD03_IRQHANDLER                USART1_IRQHandler
    
#elif (RD03_USART_NUM == 2)

    #define RD03_USARTX   			        USART2
    #define RD03_USARTX_CLK_PORT 	        RCC_APB1Periph_USART2				
    #define RD03_APBXCLKCMD   			    RCC_APB1PeriphClockCmd	
    #define RD03_BAUDRATE   			    115200
            
    #define RD03_IRQ                        USART2_IRQn
    #define RD03_IRQHANDLER                 USART2_IRQHandler
    
#elif (RD03_USART_NUM == 3)

    #define RD03_USARTX   			        USART3
    #define RD03_USARTX_CLK_PORT 	        RCC_APB1Periph_USART3				
    #define RD03_APBXCLKCMD   			    RCC_APB1PeriphClockCmd	
    #define RD03_BAUDRATE   			    115200		
            
    #define RD03_IRQ                        USART3_IRQn
    #define RD03_IRQHANDLER                 USART3_IRQHandler
    
#endif


void USARTX_NVIC_Config(void);
void USARTX_Mode_Config(void);
void USARTX_Init(void);

void USARTX_SendByte(USART_TypeDef *pusartx, uint8_t ch);
void USARTX_SendArray(USART_TypeDef *pusartx, uint8_t *array, uint16_t num);
void USARTX_SendHalfWord(USART_TypeDef *pusartx, uint16_t ch);
void USARTX_SendString(USART_TypeDef *pusartx, uint8_t *str);
void USARTX_SendString_Lenth(USART_TypeDef *pusartx, uint8_t *str,uint32_t num);
#endif /* __BSP_USART_H  */
